package com.cooper.slidingmenu.utils;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.WindowManager;

public class SampleItemSelectDialog extends DialogFragment implements
		OnClickListener {

	public interface SampleItemSelectDialogListener {

		public void onSampleItemsSelectDialogReturn(int which, int selectWhich);
	}

	public static SampleItemSelectDialog newInstance(int which, int titleRes,
			ArrayList<CharSequence> items) {
		SampleItemSelectDialog result = new SampleItemSelectDialog();
		Bundle bundle = new Bundle();
		bundle.putInt("WHICH", which);
		bundle.putInt("TITLE_RES", titleRes);
		bundle.putCharSequenceArrayList("ITEMS", items);
		result.setArguments(bundle);
		return result;
	}

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Dialog result = new AlertDialog.Builder(getActivity())
		// .setIcon(R.drawable.ic_dialog_icon)
				.setTitle(getArguments().getInt("TITLE_RES"))
				.setItems(
						getArguments().getCharSequenceArrayList("ITEMS")
								.toArray(new String[0]), this).create();
		result.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		return result;
	}

	@Override
	public void onClick(DialogInterface dialog, int which) {
		((SampleItemSelectDialogListener) getActivity())
				.onSampleItemsSelectDialogReturn(
						getArguments().getInt("WHICH"), which);

	}
}